// 签约棒球球员 P235.15-12
//Wi(S):当前剩余费用(S)下，位置i最具有价值的队员,可能不存在球员
//N:总共位置为N
//Pn:位置n的所有球员
//M[i,j](S): 总费用S,位置i->j 最优解,0<=i<=j
//R[i,j]: 选完i->j,剩余钱
/*                       Wj((R[i-1,i-1]))      i==j
 * M[i,j](R[i-1,i-1]) =  M[i,j-1](R[i-1,i-1])  Wj(R[i-1,i-1]) == Nil
 *                       max(Wj((R[i-1,i-1]))+M[i,j-1](R[j,j]),M[i,j-1](R[i-1,i-1])+Wj(R[i,j-1]))  i!=j
 */

use std::cmp;

pub struct Player{
    cost:i32,
    vorp:i32,
}
//Wi(S)
fn get_valuable_player(players:&Vec<&Player>,leftMoney:i32)->Option<&Player>{
    let mut mostValuable= Option::None;
    for p in players {
        if leftMoney >= p.cost {
            match mostValuable {
                Option::Some(mv)->
                    if(mv.vorp< p.vorp){
                        mostValuable = Option::Some(p),
                    }
                Option::None -> p,
            };
        }
    }
    mostValuable
}
// ... -> (vorp,leftMoney)
fn inter(players:&Vec<Vec<&Player>>, j:usize,allMoney:i32,leftMoney:i32)->(i32,i32){
    let valuable_player_j = get_valuable_player(players[j], leftMoney);
    if(j==0){
        return valuable_player_j.map_or((0,leftMoney), |v| (v.vorp,leftMoney-v.cost)))
    }else{
        match valuable_player_j {
            Option::None -> return inter(players,j-1,allMoney,leftMoney)
            Option::Some(player) ->
            //     
        }
    }
}
pub fn player_combine(players:&Vec<Vec<&Player>>,allMoney:i32)->i32{

}
